package cn.cocho.android.mc.activity;

import android.app.ProgressDialog;
import android.content.Context;
import android.view.Gravity;
import android.widget.Toast;

import cn.cocho.android.mc.R;
import cn.cocho.android.mc.base.ResourcesUtils;
import cn.cocho.android.mc.comp.toast.McToast;
import cn.cocho.android.mc.net.NetUtils;
import cn.cocho.android.mc.storage.ApplicationCache;

public class ActivityUtils {

	public static void showShortMessage(String msg) {
		McToast toast = new McToast(ApplicationCache.context);
		toast.setView(R.layout.mc_toast_layout, R.id.mc_toast_text, msg, Toast.LENGTH_SHORT, Gravity.BOTTOM);
	}

	public static void showLongMessage(String msg) {
		McToast toast = new McToast(ApplicationCache.context);
		toast.setView(R.layout.mc_toast_layout, R.id.mc_toast_text, msg, Toast.LENGTH_LONG, Gravity.BOTTOM);
	}

	public static void showShortMessage(int id) {
		String msg = ResourcesUtils.getString(id);
		showShortMessage(msg);

	}

	public static void showLongMessage(int id) {
		String msg = ResourcesUtils.getString(id);
		showLongMessage(msg);
	}

	public static ProgressDialog showProgressDialog(Context context, String title, String message) {
		ProgressDialog pd = new ProgressDialog(context);
		pd.setMax(100);
		pd.setTitle(title);
		pd.setMessage(message);
		pd.setCancelable(false);
		pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		return pd;
	}

	/**
	 * 检查当前网络环境是否未WIFI，如果不是则提醒用户
	 * 
	 * @param msg
	 *            提示信息
	 */
	public static void showWifiUnavailableMsg(String msg) {
		if (!NetUtils.isWifiConnected()) {
			ActivityUtils.showLongMessage(msg);
		}
	}

	/**
	 * 检查当前网络环境是否未WIFI，如果不是则提醒用户
	 * 
	 * @param stringId
	 *            字符串ID（如：R.string.msg）
	 */
	public static void showWifiUnavailableMsg(int stringId) {
		if (!NetUtils.isWifiConnected()) {
			String msg = ResourcesUtils.getString(stringId);
			ActivityUtils.showLongMessage(msg);
		}
	}

	/**
	 * 关闭所有的activity
	 * 
	 * @author HAIKANG SONG
	 */
	public static void closeAllActivity() {
//		Intent intent = new Intent();
//		intent.setAction(CommonConstants.CLOSE_ALL_ACTIVITY); // 说明动作
//		ApplicationCache.context.getApplicationContext().sendBroadcast(intent);// 该函数用于发送广播
	}

}
